package 代码记录.指定公司代码练习记录.华为_2024.分值100;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zx
 * @create 2024-02-01 23:39
 * 自己做不出来，二刷吧
 */
public class 表演赛游戏分组_17 {
    /**
     * 人家的思路，感觉递归这种思路自己肯定想不到
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] arr = scanner.nextLine().split(" ");
        int[] nums = Arrays.stream(arr).mapToInt(Integer::parseInt).toArray();

        int res = minDifference(nums, 0, 0, 0);
        System.out.println(res);
    }

    private static int minDifference(int[] nums, int index, int selected, int sum) {
        if (selected == 5) {
            int totalSum = Arrays.stream(nums).sum();
            return Math.abs(sum - (totalSum - sum));
        }
        if (index == nums.length) {
            return Integer.MAX_VALUE;
        }
        int includeCurrent = minDifference(nums, index + 1, selected + 1, sum + nums[index]);
        int excludeCurrent = minDifference(nums, index + 1, selected, sum);
        return Math.min(includeCurrent, excludeCurrent);
    }
}
